// pages/myOrder/myOrder.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow: false,
    orderStatus: '', //订单状态
    pay: '', //支付金额
    array: [],
    active: 0 //标记活动的标签
  },
  onChangeAll(event) {
    switch (event.detail.title) {
      case '全部':
        this.all()
        break;
      case '待付款':
        this.all()
        break;
      case '待收货': // console.log('待收货')
        break;
      case '退换货':
        this.returnAndExchange()
        break;
    }
  },
  all() {
    var that = this
    wx.request({
      url: app.globalData.baseUrl + '/order/findOrderByOrderStatus',
      data: {
        xcxOpenId: app.globalData.xcxOpenId,
        orderStatus: ''
      },
      success(res) {
        // console.log(res.data)
        var arr = res.data.data.rows
        var list1 = []
        var resultArr = res.data.data.rows
        var status = ''
        arr.forEach((item, index) => {
          list1 = item.orderProductList
          resultArr[index].imgSrc = app.globalData.baseUrl + '/getFile?id=' + list1[0].productSpecsDTO.specsAttId
          status = item.orderStatus
          // 获取订单状态
          switch (status) {
            case '1':
              status = '待付款'
              break;
            case '2':
              status = '待发货'
              break;
            case '3':
              status = '待收货'
              break;
            case '4':
              status = '退换中'
              break;
            case '5':
              status = '已完成'
              break;
            case '6':
              status = '已取消'
              break;
          }
          resultArr[index].status = status
        })
        that.setData({
          array: resultArr
        })
      }
    })
  },
  // 退换货接口
  returnAndExchange() {
    var that = this,
      orderCode, refundAmount, refundCause, refundRemark
    // 通过“根据订单状态获取订单信息接口”获取订单编号、退款金额、退款原因、退换货信息
    wx.request({
      url: app.globalData.baseUrl + '/order/findOrderByOrderStatus',
      data: {
        xcxOpenId: app.globalData.xcxOpenId,
        orderStatus: 4
      },
      success(res) {
        var data = res.data.data
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      active: options.name
    })
    // console.log(options)
    this.all()
  }
})